<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="机构地址" prop="mAddress">
      <el-input v-model="dataForm.mAddress" placeholder="机构地址"></el-input>
    </el-form-item>
    <el-form-item label="联系人" prop="mContact">
      <el-input v-model="dataForm.mContact" placeholder="联系人"></el-input>
    </el-form-item>
    <el-form-item label="电话" prop="mPhone">
      <el-input v-model="dataForm.mPhone" placeholder="电话"></el-input>
    </el-form-item>
    <el-form-item label="国家" prop="mCountry">
      <el-input v-model="dataForm.mCountry" placeholder="国家"></el-input>
    </el-form-item>
    <el-form-item label="省份" prop="mProvince">
      <el-input v-model="dataForm.mProvince" placeholder="省份"></el-input>
    </el-form-item>
    <el-form-item label="市" prop="mCity">
      <el-input v-model="dataForm.mCity" placeholder="市"></el-input>
    </el-form-item>
    <el-form-item label="邮编" prop="mPostcode">
      <el-input v-model="dataForm.mPostcode" placeholder="邮编"></el-input>
    </el-form-item>
    <el-form-item label="网站" prop="mWedsite">
      <el-input v-model="dataForm.mWedsite" placeholder="网站"></el-input>
    </el-form-item>
    <el-form-item label="机构级别" prop="mConstractgrade">
      <el-input v-model="dataForm.mConstractgrade" placeholder="机构级别"></el-input>
    </el-form-item>
    <el-form-item label="行业类别" prop="mIndustrytype">
      <el-input v-model="dataForm.mIndustrytype" placeholder="行业类别"></el-input>
    </el-form-item>
    <el-form-item label="重要级别" prop="mImportantgrade">
      <el-input v-model="dataForm.mImportantgrade" placeholder="重要级别"></el-input>
    </el-form-item>
    <el-form-item label="单位等级" prop="mCompanygrade">
      <el-input v-model="dataForm.mCompanygrade" placeholder="单位等级"></el-input>
    </el-form-item>
    <el-form-item label="区域级别" prop="mAreagrade">
      <el-input v-model="dataForm.mAreagrade" placeholder="区域级别"></el-input>
    </el-form-item>
    <el-form-item label="经办人" prop="mAgent">
      <el-input v-model="dataForm.mAgent" placeholder="经办人"></el-input>
    </el-form-item>
    <el-form-item label="年费" prop="mFeeofyear">
      <el-input v-model="dataForm.mFeeofyear" placeholder="年费"></el-input>
    </el-form-item>
    <el-form-item label="电子资源经费" prop="mElrefee">
      <el-input v-model="dataForm.mElrefee" placeholder="电子资源经费"></el-input>
    </el-form-item>
    <el-form-item label="采购时间" prop="mPurchasetime">
      <el-input v-model="dataForm.mPurchasetime" placeholder="采购时间"></el-input>
    </el-form-item>
    <el-form-item label="采购级别" prop="mPurchasegrade">
      <el-input v-model="dataForm.mPurchasegrade" placeholder="采购级别"></el-input>
    </el-form-item>
    <el-form-item label="采购方式" prop="mPurchaseway">
      <el-input v-model="dataForm.mPurchaseway" placeholder="采购方式"></el-input>
    </el-form-item>
    <el-form-item label="采购途径" prop="mPurchasechannel">
      <el-input v-model="dataForm.mPurchasechannel" placeholder="采购途径"></el-input>
    </el-form-item>
    <el-form-item label="分配情况" prop="mDistribution">
      <el-input v-model="dataForm.mDistribution" placeholder="分配情况"></el-input>
    </el-form-item>
    <el-form-item label="审核状态" prop="mAuditstatus">
      <el-input v-model="dataForm.mAuditstatus" placeholder="审核状态"></el-input>
    </el-form-item>
    <el-form-item label="机构类型" prop="mConstracttype">
      <el-input v-model="dataForm.mConstracttype" placeholder="机构类型"></el-input>
    </el-form-item>
    <el-form-item label="跟进状态" prop="mFowllowupstatus">
      <el-input v-model="dataForm.mFowllowupstatus" placeholder="跟进状态"></el-input>
    </el-form-item>
    <el-form-item label="备注信息" prop="mRemarks">
      <el-input v-model="dataForm.mRemarks" placeholder="备注信息"></el-input>
    </el-form-item>
    <el-form-item label="添加标签" prop="mTagging">
      <el-input v-model="dataForm.mTagging" placeholder="添加标签"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          mId: 0,
          mAddress: '',
          mContact: '',
          mPhone: '',
          mCountry: '',
          mProvince: '',
          mCity: '',
          mPostcode: '',
          mWedsite: '',
          mConstractgrade: '',
          mIndustrytype: '',
          mImportantgrade: '',
          mCompanygrade: '',
          mAreagrade: '',
          mAgent: '',
          mFeeofyear: '',
          mElrefee: '',
          mPurchasetime: '',
          mPurchasegrade: '',
          mPurchaseway: '',
          mPurchasechannel: '',
          mDistribution: '',
          mAuditstatus: '',
          mConstracttype: '',
          mFowllowupstatus: '',
          mRemarks: '',
          mTagging: ''
        },
        dataRule: {
          mAddress: [
            { required: true, message: '机构地址不能为空', trigger: 'blur' }
          ],
          mContact: [
            { required: true, message: '联系人不能为空', trigger: 'blur' }
          ],
          mPhone: [
            { required: true, message: '电话不能为空', trigger: 'blur' }
          ],
          mCountry: [
            { required: true, message: '国家不能为空', trigger: 'blur' }
          ],
          mProvince: [
            { required: true, message: '省份不能为空', trigger: 'blur' }
          ],
          mCity: [
            { required: true, message: '市不能为空', trigger: 'blur' }
          ],
          mPostcode: [
            { required: true, message: '邮编不能为空', trigger: 'blur' }
          ],
          mWedsite: [
            { required: true, message: '网站不能为空', trigger: 'blur' }
          ],
          mConstractgrade: [
            { required: true, message: '机构级别不能为空', trigger: 'blur' }
          ],
          mIndustrytype: [
            { required: true, message: '行业类别不能为空', trigger: 'blur' }
          ],
          mImportantgrade: [
            { required: true, message: '重要级别不能为空', trigger: 'blur' }
          ],
          mCompanygrade: [
            { required: true, message: '单位等级不能为空', trigger: 'blur' }
          ],
          mAreagrade: [
            { required: true, message: '区域级别不能为空', trigger: 'blur' }
          ],
          mAgent: [
            { required: true, message: '经办人不能为空', trigger: 'blur' }
          ],
          mFeeofyear: [
            { required: true, message: '年费不能为空', trigger: 'blur' }
          ],
          mElrefee: [
            { required: true, message: '电子资源经费不能为空', trigger: 'blur' }
          ],
          mPurchasetime: [
            { required: true, message: '采购时间不能为空', trigger: 'blur' }
          ],
          mPurchasegrade: [
            { required: true, message: '采购级别不能为空', trigger: 'blur' }
          ],
          mPurchaseway: [
            { required: true, message: '采购方式不能为空', trigger: 'blur' }
          ],
          mPurchasechannel: [
            { required: true, message: '采购途径不能为空', trigger: 'blur' }
          ],
          mDistribution: [
            { required: true, message: '分配情况不能为空', trigger: 'blur' }
          ],
          mAuditstatus: [
            { required: true, message: '审核状态不能为空', trigger: 'blur' }
          ],
          mConstracttype: [
            { required: true, message: '机构类型不能为空', trigger: 'blur' }
          ],
          mFowllowupstatus: [
            { required: true, message: '跟进状态不能为空', trigger: 'blur' }
          ],
          mRemarks: [
            { required: true, message: '备注信息不能为空', trigger: 'blur' }
          ],
          mTagging: [
            { required: true, message: '添加标签不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.mId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.mId) {
            this.$http({
              url: this.$http.adornUrl(`/com.emp/mechanism/info/${this.dataForm.mId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.mAddress = data.mechanism.mAddress
                this.dataForm.mContact = data.mechanism.mContact
                this.dataForm.mPhone = data.mechanism.mPhone
                this.dataForm.mCountry = data.mechanism.mCountry
                this.dataForm.mProvince = data.mechanism.mProvince
                this.dataForm.mCity = data.mechanism.mCity
                this.dataForm.mPostcode = data.mechanism.mPostcode
                this.dataForm.mWedsite = data.mechanism.mWedsite
                this.dataForm.mConstractgrade = data.mechanism.mConstractgrade
                this.dataForm.mIndustrytype = data.mechanism.mIndustrytype
                this.dataForm.mImportantgrade = data.mechanism.mImportantgrade
                this.dataForm.mCompanygrade = data.mechanism.mCompanygrade
                this.dataForm.mAreagrade = data.mechanism.mAreagrade
                this.dataForm.mAgent = data.mechanism.mAgent
                this.dataForm.mFeeofyear = data.mechanism.mFeeofyear
                this.dataForm.mElrefee = data.mechanism.mElrefee
                this.dataForm.mPurchasetime = data.mechanism.mPurchasetime
                this.dataForm.mPurchasegrade = data.mechanism.mPurchasegrade
                this.dataForm.mPurchaseway = data.mechanism.mPurchaseway
                this.dataForm.mPurchasechannel = data.mechanism.mPurchasechannel
                this.dataForm.mDistribution = data.mechanism.mDistribution
                this.dataForm.mAuditstatus = data.mechanism.mAuditstatus
                this.dataForm.mConstracttype = data.mechanism.mConstracttype
                this.dataForm.mFowllowupstatus = data.mechanism.mFowllowupstatus
                this.dataForm.mRemarks = data.mechanism.mRemarks
                this.dataForm.mTagging = data.mechanism.mTagging
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/com.emp/mechanism/${!this.dataForm.mId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'mId': this.dataForm.mId || undefined,
                'mAddress': this.dataForm.mAddress,
                'mContact': this.dataForm.mContact,
                'mPhone': this.dataForm.mPhone,
                'mCountry': this.dataForm.mCountry,
                'mProvince': this.dataForm.mProvince,
                'mCity': this.dataForm.mCity,
                'mPostcode': this.dataForm.mPostcode,
                'mWedsite': this.dataForm.mWedsite,
                'mConstractgrade': this.dataForm.mConstractgrade,
                'mIndustrytype': this.dataForm.mIndustrytype,
                'mImportantgrade': this.dataForm.mImportantgrade,
                'mCompanygrade': this.dataForm.mCompanygrade,
                'mAreagrade': this.dataForm.mAreagrade,
                'mAgent': this.dataForm.mAgent,
                'mFeeofyear': this.dataForm.mFeeofyear,
                'mElrefee': this.dataForm.mElrefee,
                'mPurchasetime': this.dataForm.mPurchasetime,
                'mPurchasegrade': this.dataForm.mPurchasegrade,
                'mPurchaseway': this.dataForm.mPurchaseway,
                'mPurchasechannel': this.dataForm.mPurchasechannel,
                'mDistribution': this.dataForm.mDistribution,
                'mAuditstatus': this.dataForm.mAuditstatus,
                'mConstracttype': this.dataForm.mConstracttype,
                'mFowllowupstatus': this.dataForm.mFowllowupstatus,
                'mRemarks': this.dataForm.mRemarks,
                'mTagging': this.dataForm.mTagging
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
